package com.howtographql.hackernews.link;

/**
 * 功能说明：
 *
 * @author xiaoyu
 * @date 2019/2/21
 */

import com.coxautodev.graphql.tools.GraphQLResolver;
import com.howtographql.hackernews.user.User;
import com.howtographql.hackernews.user.UserRepository;

/**
 *
 * @description
 * @version 1.0
 * @author Administrator
 * @date 2019/2/21 15:00
 *
 */
public class LinkResolver implements GraphQLResolver<Link> {
    private final UserRepository userRepository;

    public LinkResolver(UserRepository userRepository) {
        this.userRepository = userRepository;
    }

    public User postedBy(Link link) {
        if (link.getUserId() == null) {
            return null;
        }
        return userRepository.findById(link.getUserId());
    }
}
